//导入发邮件模块
const nodemailer = require('nodemailer')

//创建发邮件配置
let transport = nodemailer.createTransport({
    //配置参数
    host: 'smtp.126.com',
    port: 465,
    //当端口为465时，secure需要设置为true
    secure: true,
    //身份授权
    auth: {
        user: 'yutongshuxue@126.com',
        //授权码
        pass: 'VJIUSRYZHWQVUNFO'
    }
})

function sendEmail(emails, code, fn) {
    //emails 类型string shen@126.com,youremail@126.com....
    transport.sendMail({
        from: 'yutongshuxue@126.com',
        to: emails,
        //主题
        subject: '邮箱验证码',
        //验证码内容
        text: `你的邮箱验证码是${code}`
    }, fn)
}

module.exports = sendEmail